#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include "client.h"

int chat_to (const char *from, const char *to, const char *msg)
{	
	int tmp;
	tmp = CHAT_TO;
	send(sock_fd, &tmp, sizeof(int), 0);

	tmp = strlen(from);
	send(sock_fd, &tmp, sizeof(int), 0);
	send(sock_fd, from, tmp, 0);

	tmp = strlen(to);
	send(sock_fd, &tmp, sizeof(int), 0);
	send(sock_fd, to, tmp, 0);

	tmp = strlen(msg);
	send(sock_fd, &tmp, sizeof(int), 0);
	send(sock_fd, msg, tmp, 0);
	
	recv(sock_fd, &tmp, sizeof(int), 0);
	return tmp;
}

#ifdef DEBUG
int main (int argc, char* argv[])
{
	if ( argc != 3)
	{
		printf ("usage: char_to name msg\n");
		exit (EXIT_FAILURE);
	}
	net_init();
	printf("res\t%d\n", chat_to(argv[1], argv[2]));
}
#endif

